﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnvDTE;
using SPVisualDev.VSAddin.Dialogs;

namespace SPVisualDev.VSAddin
{
    public partial class SettingsPageGeneral : UserControl, IDTToolsOptionsPage
    {
        internal const string C_PARAM_SKIP_FILES_PUSH_DOWN = "SkipFilesPushDown";
        internal const string C_PARAM_PUSH_DOWN_FILES = "PushDownFiles";


        private DTE m_dte;

        public SettingsPageGeneral()
        {
            InitializeComponent();
        }

        #region IDTToolsOptionsPage Members

        public void GetProperties(ref object PropertiesObject)
        {

        }

        public void OnAfterCreated(DTE DTEObject)
        {
            try
            {
                m_dte = DTEObject;

                string push_down_on_save = Common.GetUserRegistryParam(C_PARAM_PUSH_DOWN_FILES, true);
                if (!string.IsNullOrEmpty(push_down_on_save))
                {
                    this.chkPushDownEnabled.Checked = bool.Parse(push_down_on_save);
                }
                else
                {
                    this.chkPushDownEnabled.Checked = true;
                }

                string skip_files_push_down = Common.GetUserRegistryParam(C_PARAM_SKIP_FILES_PUSH_DOWN, true);
                if (skip_files_push_down == null)
                    txtSkipFilesPushDown.Text = Common.C_IGNORE_FILE_TYPE_ON_PUSH_DOWN;
                else
                    txtSkipFilesPushDown.Text = skip_files_push_down;

            }
            catch (Exception ex)
            {
                DialogError.ShowError(ex);
            }
        }

        public void OnCancel()
        {
        }

        public void OnHelp()
        {
            throw new NotImplementedException();
        }

        public void OnOK()
        {
            try
            {
                Common.SetUserRegistryParam(C_PARAM_SKIP_FILES_PUSH_DOWN, txtSkipFilesPushDown.Text);
                Common.SetUserRegistryParam(C_PARAM_PUSH_DOWN_FILES, chkPushDownEnabled.Checked.ToString());
            }
            catch (Exception ex)
            {
                DialogError.ShowError(ex);
            }
        }

        #endregion
    }
}
